//
//  BaseViewController.swift
//  AnShiPai
//
//  Created by 马瑜 on 2017/7/7.
//  Copyright © 2017年 马瑜. All rights reserved.
//

import UIKit

class BaseViewController: UIViewController, UIGestureRecognizerDelegate {

    override func viewDidLoad() {
        super.viewDidLoad()
        self.navigationController?.interactivePopGestureRecognizer!.delegate = self
        self.navigationController?.navigationBar.barStyle = UIBarStyle.black
//        navigationController!.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.white]
        self.navigationBarColor = GlobalColor
        self.automaticallyAdjustsScrollViewInsets = false
        removeCustomNavBottomLine()
    }
    
    func setBackBarBotton (){
        let backItem = UIBarButtonItem(image: UIImage(named: "Home-BackIcon"), style: .plain, target: self, action: #selector(backAction(_:)))
        self.navigationItem.leftBarButtonItem = backItem
    }
    
    @objc func backAction(_ sender:UIButton) {
        backToPrevious()
    }
    
    //MARK: 移除自定义navigationBar 下面的黑线
    func removeCustomNavBottomLine() {
        (self.navigationController?.navigationBar)?.getBottomLineView()?.isHidden = true
    }
    
    //返回true表示所有相同类型的手势辨认都会得到处理
    func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer,
                           shouldRecognizeSimultaneouslyWith otherGestureRecognizer:
        UIGestureRecognizer) -> Bool {
        return true
    }
    
    //是否允许手势
    func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
        if (gestureRecognizer == self.navigationController?.interactivePopGestureRecognizer) {
            //只有二级以及以下的页面允许手势返回
            return (self.navigationController?.viewControllers.count)! > 1
        }
        return true
    }
    
    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        self.view.endEditing(true)
    }
    

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
}
